# -*- coding: utf-8 -*-

import asyncio
import httpx
from backend.mock_tools import openapi_to_tools
import json

print("Hello, World!")

async def fetch_openapi():
    async with httpx.AsyncClient() as http_client:
        resp = await http_client.get("http://127.0.0.1:8000/openapi.json")
        print("[Agent] 获取到 openapi.json")
        # print(resp.text)
        openapi_schema = json.loads(resp.text)
        # print(openapi_schema)
        print("[Agent] 获取到 openapi schema")
        tools = openapi_to_tools(openapi_schema)
        print("[Agent] tools schema:", json.dumps(tools))
        return resp.text
        
# To run the async function
if __name__ == "__main__":
    asyncio.run(fetch_openapi())